package com.sky.robot.commons.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class PropertiesUtils {

    private static Properties properties = new Properties();
    private static Map<String, String> PROPER_MAP = new HashMap<>();



    static {
        InputStream is = null;
        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application-generator.properties" );
            properties.load(is);

            for (Object o : properties.keySet()) {
                String next = (String) o;
                PROPER_MAP.put(next, properties.getProperty(next));
            }

            System.out.println(PROPER_MAP);

        } catch (Exception ignored) {

        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException i) {
                    i.printStackTrace();
                }
            }
        }
    }

    public static String getString(String key) {
        return PROPER_MAP.get(key);
    }

    public static void main(String[] args) {
        System.out.println(getString("spring.application.name"));
    }
}
